package com.felton.springboot.shrio.controller;

import com.felton.springboot.shrio.entity.User;
import com.felton.springboot.shrio.model.LoginResult;
import com.felton.springboot.shrio.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类  名：com.felton.springboot.shrio.controller.LoginController
 * 类描述：todo
 * 创建人：liurui
 * 创建时间：2020/6/10 13:27
 * 修改人：
 * 修改时间：
 * 修改备注：
 *
 * @author liurui
 * @version 1.0
 */


@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @GetMapping(value = "/login")
    public String login() {

        return "登录页";
    }

    @PostMapping(value = "/login")
    public String login(@RequestBody User user) {
        System.out.println("login()");
        String userName = user.getUserName();
        String password = user.getPassword();
        LoginResult loginResult = loginService.login(userName, password);
        if (loginResult.isLogin()) {
            return "登录成功";
        } else {
            return "登录失败：" + loginResult.getResult();
        }
    }

    @GetMapping(value = "/index")
    public String index() {
        return "主页";
    }

    @GetMapping(value = "/logout")
    public String logout() {
        return "退出";
    }

    @GetMapping("/403")
    public String unauthorizedRole() {
        return "没有权限";
    }
}
